/**
 * @author yexiebao
 * @date 2025/5/15
 */
public class DeleteLinkListNode {
    //常规解法
    public ListNode deleteNode(ListNode head,int val){
        if(head != null&&head.val == val){
            head = head.next;
        }
        ListNode curr = head;
        while(curr != null && curr.next != null){
            if(curr.next.val == val){
                curr.next = curr.next.next;
            }else{
                curr = curr.next;
            }
        }
        return head;
    }
    //递归解法
    public ListNode deleteNodeUsingRecursion(ListNode head,int val){
        //1.递归结束条件
        if(head == null){
            return head;
        }
        //2.递归调用
        head.next = deleteNodeUsingRecursion(head.next,val);
        //3.返回值
        return head.val == val ? head.next : head;
    }
}